package ua.org.nuos.sdms.clientgui.server.validators;

import com.vaadin.data.validator.AbstractValidator;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by IntelliJ IDEA.
 * User: dio
 * Date: 14.11.11
 * Time: 21:35
 * To change this template use File | Settings | File Templates.
 */
public class PasswordValidator extends AbstractValidator {

    private final String REGEXP = "[a-zA-Z0-9\\-\\._\\?\\,\\'/\\\\+&%\\$#\\=~]+";

    public PasswordValidator(String errorMessage) {
        super(errorMessage);
    }

    @Override
    public boolean isValid(Object o) {
        String password = (String) o;
        Pattern pattern = Pattern.compile(REGEXP);
        Matcher matcher = pattern.matcher(password);
        return matcher.matches();
    }
}
